/*
 * Copyright (c) 2001-2018 GuaHao.com Corporation Limited. All rights reserved.
 * This software is the confidential and proprietary information of GuaHao Company.
 * ("Confidential Information").
 * You shall not disclose such Confidential Information and shall use it only
 * in accordance with the terms of the license agreement you entered into with GuaHao.com.
 *
 */
package com.bolt.convention.validation.validators;


import com.bolt.convention.validation.constraints.ChineseName;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * 中文姓名校验，允许间隔号
 */
public class ChineseNameValidator implements ConstraintValidator<ChineseName, String> {

    @Override
    public void initialize(ChineseName constraintAnnotation) {

    }

    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        if (value == null) {
            return true;
        }
        char[] ch = value.toCharArray();
        for (int i = 0; i < ch.length; i++) {
            char c = ch[i];
            //间隔号编码为'\u00B7'
            if (!CharValidatorUtil.isChinese(c) && c != '·') {
                return false;
            }
        }
        return true;
    }
}
